class Rudoku::Elimination
  attr_reader :rule, :field, :candidate, :params
  
  def initialize(rule, field, candidate, params)
    @rule, @field, @candidate, @params = rule, field, candidate, params
    @performed = false
  end
  
  def perform
      @field.remove(@candidate)
      @performed = true
  end
  
  def reason # get a nicely formatted reason message for this particular elimination
    return nil if @rule.reason.nil?
    
    @rule.reason.gsub(/\:[a-zA-Z0-9]*/) do |match|
      match.gsub!(":", "")
      
      case match
      when "candidate"
        @candidate
      when "field"
        @field.position
      else
        @params[match.to_sym]
      end
    end
  end
  
  def performed?
    @performed
  end
end

